﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
using Deepseek_Robot.Modules.Models;
using Deepseek_Robot.Modules.ViewModels;

namespace Deepseek_Robot
{
    public class MainWindowViewModel : ViewModelBase
    {
        public ObservableCollection<string> NavigationItems { get; set; }
        // 缓存各个 ViewModel 实例
        private readonly RobotConnectionViewModel _robotConnectionViewModel;
        private readonly AIControlViewModel _aiControlViewModel;
        private readonly RunningLogViewModel _runningLogViewModel;
        private readonly ChartViewModel _chartViewModel;
        private readonly RobotParameterViewModel _robotParameterViewModel;

        private object _currentPage = new RobotConnectionViewModel();
        public object CurrentPage
        {
            get => _currentPage;
            set => SetProperty(ref _currentPage, value);
        }

        public MainWindowViewModel()
        {
            NavigationItems = new ObservableCollection<string> {  "AI 控制", "机器人参数", "运行日志", "运动路径" }; //"机器人连接",
            // 在构造函数中提前实例化 ViewModel
            _robotConnectionViewModel = new RobotConnectionViewModel();
            _aiControlViewModel = new AIControlViewModel();
            _runningLogViewModel = new RunningLogViewModel();
            _chartViewModel = new ChartViewModel();
            _robotParameterViewModel = new RobotParameterViewModel();

            NavigateTo("运行日志");

            // 注册页面跳转消息
            WeakReferenceMessenger.Default.Register<NavigatePageMessage>(this, (r, m) =>
            {
                NavigateTo(m.PageName);
            });
        }

        public  void NavigateTo(string item)
        {
            switch (item)
            {
                case "机器人连接":
                    CurrentPage = _robotConnectionViewModel;
                    break;
                case "AI 控制":
                    CurrentPage = _aiControlViewModel;
                    break;
                case "运行日志":
                    CurrentPage = _runningLogViewModel;
                    break;
                case "运动路径":
                    CurrentPage = _chartViewModel;
                    break;
                case "机器人参数":
                    CurrentPage = _robotParameterViewModel;
                    break;
            }
        }
    }
}